﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace MagicFight
{
    public class ArcaneBeam : Magic
    {
        int duration = Def.ArcaneBeamDef.Duration;

        Beam beam = null;
        bool casted = false;

        public ArcaneBeam(Character caster)
            : base(caster, Def.ArcaneBeamDef.N)
        {
        }

        public override void Casting(GameTime gameTime)
        {
            if (caster.countered) { caster.castTimer = 1; caster.countered = false; alive = false; caster.isCasting = false; return; }
            caster.castTimer += gameTime.ElapsedGameTime.TotalMilliseconds;
            if (caster.castTimer > caster.castTime)
            {
                if (casted) // aqui significa que já castou e já acabou o lifeTime do beam
                {
                    caster.castTimer = 1;
                    isCasting = caster.isCasting = false;
                    beam.alive = alive = false;
                }
                else // aqui significa que acabou de castar
                {
                    caster.castTimer = 1;
                    caster.castTime = duration;
                    casted = true;
                    beam = new Beam(caster);
                    ps.gameObjects.Add(beam);
                }
            }
        }

        public override void Effect(GameTime gameTime)
        {
        }
    }
}

/*
            Vector2 beamOrigin = new Vector2(beam_body.Width / 2, beam_body.Height / 2);
            Vector2 pos = Position;
            Vector2 nextPos = pos + 30 * direction;
            spriteBatch.Draw(beam_start, nextPos, null, Color.White, rotation, beamOrigin, 1, SpriteEffects.None, 0);
            nextPos = nextPos + 30 * direction;
            Vector2 nextNextPos = nextPos + 30 * direction;
            while (nextNextPos.X > 100 && nextNextPos.X < 1180 && nextNextPos.Y > 100 & nextNextPos.Y < 620)
            {
                spriteBatch.Draw(beam_body, nextPos, null, Color.White, rotation, beamOrigin, 1, SpriteEffects.None, 0);
                nextPos = nextPos + 30 * direction;
                nextNextPos = nextPos + 30 * direction;
            }
            spriteBatch.Draw(beam_end, nextPos, null, Color.White, rotation, beamOrigin, 1, SpriteEffects.None, 0);
*/